<?php /*a:2:{s:55:"G:\project\insure\view\admin\company\company_edit.phtml";i:1593773422;s:39:"G:\project\insure\view\admin\base.phtml";i:1593775922;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>HQadmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/hqui/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/hqui/module/admin.css?v=316"/>
  <link rel="stylesheet" href="/static/css/fonts.css">
  <link rel="stylesheet" href="/static/css/base.css">
  
</head>
<style>
    .layui-form-label{
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
        min-height: 36px
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        
<link rel="stylesheet" href="/static/dist/basic.min.css" />
<link rel="stylesheet" href="/static/dist/dropzone.min.css" />

<div class="layui-card" style="width: 1000px;height: 1600px">
    <div class="layui-card-body">
        <form action="<?php echo request()->url(); ?>" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">保险公司名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="<?php echo htmlentities((isset($data['name']) && ($data['name'] !== '')?$data['name']:'')); ?>" autocomplete="off" placeholder="请输入公司名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择机构</label>
                <div class="layui-input-block">
                    <select name="aid" lay-verify="required">
                        <?php if(!empty($aid)): ?>
                        <option value="<?php echo htmlentities($aid); ?>"><?php echo htmlentities($aname); ?></option>
                        <?php else: if(is_array($agency) || $agency instanceof \think\Collection || $agency instanceof \think\Paginator): $i = 0; $__LIST__ = $agency;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <option value="<?php echo htmlentities($vo['id']); ?>"><?php echo htmlentities($vo['name']); ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                        <?php endif; ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="memo" placeholder="请输入内容" class="layui-textarea"><?php echo htmlentities((isset($data['memo']) && ($data['memo'] !== '')?$data['memo']:'')); ?></textarea>
                </div>
            </div>

            <input name="isedit" value="<?php echo input('isedit'); ?>" hidden="hidden">


            <?php if(input('isedit') == 1): ?>
            <input value="<?php echo htmlentities($data['id']); ?>" hidden="hidden" name="id">
            <?php endif; ?>
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="i" id="sub" >保存</button>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script src="/static/js/clipboard.js"></script>
<script src="/static/dist/dropzone.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.serializeJSON/2.6.2/jquery.serializejson.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"> </script >


    </div>
</div>

<script type="text/javascript" src="/static/hqui/libs/layui/layui.all.js"></script>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/layui.base.js"></script>
<script type="text/javascript" src="/static/hqui/js/common.js?v=316"></script>
<script type="text/javascript">

    //工具函数 将表单里数据 序列化成json对象
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };

    function refreshArea(_formWin){
        var _formWinObj = $("#layui-layer"+_formWin);
        var w = _formWinObj.outerWidth();
        var h = _formWinObj.outerHeight();
        var l = ($(document).width()-w)/2;
        var t = ($(window).height()-h)/2;
        _formWinObj.css({
            "left":l,
            "top":t
        });
    }



    $(document).on('click',"#edit",function(){
        console.log($(this).data('id'));
        console.log($('#editurl').val() + '&id=' + $(this).data('id'));
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#editurl').val() + '&id=' + $(this).data('id'),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $('#add').click(function(){
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#addurl').val(),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $("#agency").change(function(){
        $('#addurl').val($('#oriaddurl').val());
        var href = $('#addurl').val();
        href += '&aid='+$(this).val();
        $('#addurl').val(href);
        $.ajax({
            url:'getCompany',
            data:{'id':$(this).val()},
            method:'post',
            success:function(res){
                $('#company').children().remove();
                let data = JSON.parse(res);
                let str = '<option value="">全部</option>';
                for(let i in data){
                    str += ' <option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
                }
                $('#company').append(str);
            }
        });
    });

    $('#company').change(function(){

        var href = $('#addurl').val();
        href += '&cid='+$(this).val();
        $('#addurl').val(href);
    })

</script>

<script>
    $('#sub').click(function(){
        if($('input[name="name"]').val() == ''){
            layer.open({
                content: '保险公司名称必填' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="aid"]').val() == ''){
            layer.open({
                content: '机构必选' //这里content是一个普通的String
            });
            return;
        }

        var data = $('form').serializeJson();
        $.ajax({
            url:'company_add',
            data: data,
            method:'post',
            success:function(res){
                layer.open({
                    content: res.msg, //这里content是一个普通的String
                    end: function(){ //此处用于演示
                        if(res.code == 1){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        }
                    }
                });


            }
        });

        //$('form').submit();
    })
</script>

</body>
</html>